package com.dhemery.mack.actions;

import org.eclipse.core.runtime.IAdapterFactory;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.ui.IWorkbenchPage;

import com.dhemery.mack.adapters.EditorLauncher;
import com.dhemery.mack.adapters.ImageDescriptorSource;
import com.dhemery.mack.application.MackPlugin;
import com.dhemery.mack.model.Node;

public class OpenAction extends ExplorerViewAction {
	private static final String name = "Open";
	public static final String ID = MackPlugin.COMMAND_ID_PREFIX + name;
	private static final String imagePath = "icons/16/text_edit.png";

	public OpenAction(
			IWorkbenchPage page,
			TreeViewer viewer,
			IAdapterFactory factory,
			ImageDescriptorSource imageDescriptorSource) {
		super(name, ID, imagePath, page, viewer, factory, imageDescriptorSource);
	}

	@Override
	protected void execute(IWorkbenchPage page, IAdapterFactory factory, Object[] selectedObjects) {
		EditorLauncher launcher = new EditorLauncher(page, factory);
		for(Object node : selectedObjects) {
			launcher.edit((Node)node);
		}
	}

	@Override
	protected boolean isSelected(Object[] selectedObjects) {
		return selectedObjects.length > 0;
	}
}
